<div class="content-wrapper"> 
  <section class="content-header">
    <h1>导入<small>预览</small></h1>
  </section>
  <section class="content">
    <table class="datatable table table-striped table-hover" id="preview">
      <thead>
        <tr>
          <th class="hidden-xs">版本号</th>
          <th class="hidden-xs">应用名</th>
          <th class="hidden-xs">启动成功次数</th>
          <th class="hidden-xs">启动失败次数</th>
          <th class="hidden-xs">崩溃率</th>
          <th class="hidden-xs">发布日期</th>
          <th class="hidden-xs">类型</th>
          <th class="hidden-xs">来源</th>
          <th class="hidden-xs">迭代版本特点</th>
          <th class="hidden-xs">操作</th>
        </tr>
      </thead>
      <tbody>
        <% @preview_versions.each do |app_version| %>
        <tr>
          <td class="hidden-xs"><%= app_version.version %></td>
          <td <%= (app_version.app.name rescue '-') == '-' ? 'class=btn-danger' : 'class=hidden-xs' %>><%= app_version.app.name rescue '不存在该应用' %></td>
          <td class="hidden-xs"><%= app_version.success %></td>
          <td class="hidden-xs"><%= app_version.fails %></td>
          <td <%= (0..100).include?((((app_version.fails.to_f/(app_version.fails + app_version.success)).round(2))*100).to_i) ? 'class=hidden-xs' : 'class=btn-danger' %>><%= (((app_version.fails.to_f/(app_version.fails + app_version.success)).round(2))*100).to_i %></td>
          <td class="hidden-xs"><%= app_version.released_date.strftime('%y-%m-%d') rescue '-' %></td>
          <td class="hidden-xs"><%= app_version.typehood %></td>
          <td class="hidden-xs"><%= app_version.source %></td>
          <td class="hidden-xs"><%= app_version.description %></td>
          <td class="hidden-xs"></td>
        </tr>
        <% end %>
      </tbody>
    </table>
    <% if @unknown_app %>
        <a href="/versions">
          <%= submit_tag '导入数据有误,请返回导入页面，重新导入', class: 'disable btn btn-danger btn-flat btn-block' %>
        </a>
    <% else %>
      <%= form_tag({action: :import}) do %>
        <%= hidden_field_tag 'preview_versions' %>
        <%= submit_tag '导入', class: 'btn btn-primary btn-flat btn-block', id: 'import-issuces-btn', data: {disable_with: '导入中...'} %>
      <% end %>
    <% end %>
  </section>
</div>
<script>
  $('#preview').DataTable();
  $('#preview_versions').val('<%= raw @preview_versions.to_json %>');
</script>
